<?php
class AppController extends Controller {

    var $helpers = array(
        'Html',
        'Form',
        'Ajax',
        'Session',
        'Javascript',
        'Text',
        'Time',
        'Cereza'
    );

    var $components = array(
//        'Security',
//        'Acl',
//	'Auth',
        'Session',
        'RequestHandler',
    );

	var $uses = array(
		'Persona',
		'Instructor',
		'Grupo',
		'GruposPersonas'
	);


	function cargarLayouts () {

//		if($id = $this->Session->read('Auth.Persona.rol_id')){
//			if($id == 0){
//				$this->layout = '0';
//			}
//			else if($id == 1){
//				$this->layout = '1';
//			}
//			else if($id == 2){
//				$this->layout = '2';
//			}
//		}

	}

	function crearSessiones() {
        if ($this->Session->check('Grupo.id')) {
            foreach($this->Session->read('Grupo.id') as $dato){
//				if($dato != 1 || $dato != 2){
//					$this->Auth->deny('edit');
//				}
//				echo $dato;
            }

        }

		if($this->Session->read('Auth')){
			$this->Persona->recursive = 1;
			$data = $this->Persona->find('first', array('conditions' => array('Persona.id' => $this->Session->read('Auth.Persona.id'))));

			//Sessiones de Instructor
			if(is_array($data['Instructor']) && isset($data['Instructor'])){
				foreach($data['Instructor'] as $indice => $valor){
					$this->Session->write("Instructor.{$indice}", $valor);
				}
//				pr($this->Session);
			}



			//Sessiones de Grupo
			if(is_array($data['Grupo']) && isset($data['Grupo'])){
				$i = 0;
				foreach($data['Grupo'] as $grupo){
					$this->Session->write("Grupo.id.{$i}", $grupo['id']);
					//$this->Session->write("Grupo.nombre.{$i}", $grupo['nombre']);
					$i++;
				}
			}

//			pr($this->Session->read());

		}

    }

      /*
 	function beforeFilter(){

   		parent::beforeFilter();

   		$this->Auth->deny('add');

		$this->Session->write('Auth.redirect', null);

		if ($this->RequestHandler->isAjax()) {
            $this->layout = 'ajax';
		//carga los layouts en cada REQUEST
		$this->cargarLayouts();

		//Verifica quien esta en sesion
		$this->crearSessiones();

   }
        }

	function beforeFilter() {
		//Configure AuthComponent
		$this->Auth->userModel = 'Usuario';
		$this->Auth->fields = array(
			'username' => 'usuario',
			'password' => 'clave'
		);
		Security::setHash('md5');
		//$this->Auth->actionPath = "Controllers/";		
		$this->Auth->authorize = 'actions';
		$this->Auth->authError = "Lo siento, no tiene permisos para acceder a este proceso.";
		$this->Auth->loginAction = array('controller' => 'usuarios', 'action' => 'login');
		$this->Auth->logoutRedirect = array('controller' => '/');
		$this->Auth->loginRedirect = array('controller' => 'eventos', 'action' => 'index');
		
	}*/

}
?>